#Harris 1972 Presidential Election Survey, study no. 2236
## packages 

require("dplyr")
require("readstata13")

## set working directory to replicaiton
## package 

## download data
survey <- read.dta13("Harris_Data/Harris 1972 Presidential Election Survey, study no. 2236/harris_s2236_spss.dta")

## pid
survey$pid <- c(1:nrow(survey))
class(survey$pid)

## study number
survey$study <- as.character(2236)
class(survey$study)

## year
survey$year <- 1972
class(survey$year)

## geographpic data
survey$urban <- NA

## region 
survey$region <- dplyr::recode(survey$S11,
                               `6` = "Midwest",
                               `3` = "South",
                               `2` = "East",
                               `7` = "West",
                               `1` = "East",
                               `4` = "South",
                               `5` = "Midwest",
                               `8` = "West")

## respondent name
summary(survey$F1)
survey$hh <- as.character(survey$F1)

## inequality increasing
summary(survey$P7_A)
survey$inequality <- as.character(survey$P7_A)

## inequality variable version
survey$inequality.variable <- 1
class(survey$inequality.variable)

## union 
survey$union.self <- as.character(survey$F7_1)
survey$union.self[survey$F7_4 == "Yes"] <- "Not Sure"

survey$union.other <- as.character(survey$F7_2)
survey$union.other[survey$F7_4 == "Yes"] <- "Not Sure"

## Are you employed? what kind of employment?
summary(survey$F2A)
survey$employed <- as.character(survey$F2A)
class(survey$employed)

## employed.self
survey$employed.self <- NA

## Occupation
summary(survey$F2B)
survey$occupation <- as.character(survey$F2B)
class(survey$occupation)

## occupation self
survey$occupation.self <- NA

## household size
survey$hhsize <- NA

## Education
summary(survey$F5)
survey$educ <- as.character(survey$F5)

## Income
summary(survey$F6)
survey$income <- as.character(survey$F6)
summary(survey$income)
class(survey$income)

## Age 
summary(survey$P1E)
survey$age <- as.character(survey$P1E)
summary(survey$age)

## race
summary(survey$F8)
survey$race <- as.character(survey$F8)
summary(survey$race)

## politics 
survey$party <- as.character(survey$P1C)
summary(survey$party)
table(survey$party)

## ideology
survey$ideology <- NA
summary(survey$ideology)

## gender
summary(survey$F9)
survey$gender <- as.character(survey$F9)
table(survey$gender)

## religion
survey$religion <- as.character(survey$F3)
summary(survey$religion)

## factuals
survey$factual1 <- NA
survey$factual2 <- NA
survey$factual3 <- NA

## alienation index
survey$dontcare <- as.character(survey$P7_B)
survey$dontcount <- as.character(survey$P7_C)
survey$leftout <- as.character(survey$P7_E)

## question place
survey$question_place <- "after party"

### put together data set
survey_2236 <- survey[,c("pid", "study", "year", "urban", "region", "hh",
                         "inequality", "inequality.variable", "union.self", "union.other",
                         "employed", "employed.self", "occupation", "occupation.self", "hhsize", "educ", "income", 
                         "age", "race", "party", "ideology", "gender", "religion",
                         "factual1", "factual2", "factual3", "dontcare", "dontcount", "leftout",
                         "question_place")]

## save dataset in folder 
#saveRDS(survey_2236, file = "Harris_Data/survey_2236.rds")



